﻿<!DOCTYPE html>
<html>
<head>
  <title>添加栏目</title>
</head>
<body>
 
    <div class="tabarea1">
        <div id="area" class="area" style="overflow-y:auto;">
                <form action="" method="post">
                    <div class="form" id="category_entity_form">
                        <input type="hidden" field="Lft" />
                        <dl>
                            <dt>上级栏目：</dt>
                            <dd>
                                <span class="input">
                                    <select field="parentLft" class="tb_normal" id="pcata">
                                        <option value="1" style="color:Red">一根目录一</option>
                                        ${categories}
                                    </select>
                                </span>
                                <span class="desc" style="color:Red">注:上级栏目指定后,不可修改!</span>
                            </dd>
                        </dl>

                        <dl>
                            <dt>名称：</dt>
                            <dd>
                                <input type="text" class=" ui-validate" summary="{required:'不能为空',lenerr:'长度不能超过50位'}" field="Name" id="name" size="50" />
                            </dd>
                        </dl>
                        <dl><dt>栏目标识：</dt><dd><input type="text" class=" ui-validate" field="Tag" id="tag" size="20" /><a style="margin-left:5px" href="javascript:;" summary="{required:'不能为空',strerr:'长度为50位以下的字母，数字，下划线和连接线的组合'}">自动标识</a> <br /><span class="desc" style="padding-left:60px">建议手动填写,用于调用数据的唯一标识,且显示在地址栏中,如http://www.ops.cc/news/,news就是一个标识</span></dd></dl>
                        <dl style="display:none"><dt>模块：</dt><dd><select class="tb_normal" field="ModuleId">${categoryTypes}</select></dd></dl>

                        <dl><dt>视图：</dt><dd><select field="CategoryTemplate" id="CategoryTemplate" class="tb_normal"><option value="">一默认一</option>${category_tpls} </select><span class="desc">注：默认则使用模块的视图设置</span></dd></dl>


                        <dl><dt>文档视图：</dt><dd><select field="CategoryArchiveTemplate" id="CategoryArchiveTemplate" class="tb_normal"> <option value="">一默认一</option>${archive_tpls}</select><span class="desc">注：默认则使用模块（或文档）的视图设置</span></dd></dl>

                        <dl><dt>序号：</dt><dd><input class=" ui-validate" isnumber="true" field="OrderIndex" style="width:50px;" value="0" /></dd></dl>
                        <dl>
                            <dt>位置定向：</dt>
                            <dd>
                                <input class=" ui-validate" length="[0,150]" name="location" field="Location" />
                                访问栏目页面，跳转到的地址。默认不填写，不跳转!
                            </dd>
                        </dl>
                        <dl><dt>标题：</dt><dd><textarea class=" ui-validate" length="[0,100]" field="PageTitle" name="PageTitle" style="width:500px;height:25px;"></textarea></dd></dl>
                        <dl><dt>关键字：</dt><dd><textarea class=" ui-validate" length="[0,100]" field="Keywords" style="width:500px;height:25px;"></textarea></dd></dl>
                        <dl><dt>描述：</dt><dd><textarea class=" ui-validate" length="[,200]" field="Description" style="width:500px;height:75px;"></textarea></dd></dl>

                        <dl><dt>&nbsp;</dt><dd><a id="btn" class="btn" href="javascript:;">新增</a></dd></dl>

                    </div>
</form>
        </div>

    </div>
  <script type="text/javascript">
        var tag = cms.$("tag"),
        name = cms.$("name");

        tag.onblur=function(){
          if(tag.value==''){
              cms.validator.setTip(tag.nextSibling, false,'required');
          }else{
             tag.value=tag.value.toLowerCase();
             if(!/^[a-z0-9_-]{1,50}$/.test(tag.value)){
                 cms.validator.setTip(tag.nextSibling, false, 'strerr');
             }else{
                 cms.validator.removeTip(tag.nextSibling);
             }
          }
        };

        name.onblur = function () {
            if (name.value == '') {
                cms.validator.setTip(name, false, 'required');
            } else {
                if (name.value.length > 50) {
                    cms.validator.setTip(name, false, 'lenerr');
                } else {
                    cms.validator.removeTip(name);
                }
            }
        };
        tag.nextSibling.onclick = function () {
            var e = this;
            var txt = this.innerHTML;
            var _title = name.value;
            if (_title == '') {
                cms.validator.setTip(e, false, null, '请先输入栏目名称!');
            } else {
                this.innerHTML = '获取中...';
                cms.xhr.post('?', 'module=archive&action=getarchivealias&title=' + encodeURIComponent(_title), function (result) {
                    e.previousSibling.value = result.toLowerCase();
                    e.previousSibling.onblur();
                    e.innerHTML = txt;
                }, function () {
                    cms.validator.setTip(e, false, null, '获取失败,请重试!');
                });
            }
        };


        cms.$('btn').onclick = function () {
            if (cms.validator.validate()) {
                var data = cms.json.toObject('category_entity_form');
                cms.xhr.jsonAjax(
                     '${url}',
                     data,
                     function (json) {
                         if (json.result) {
                             if (window.Fn.loadData) {
                                 //Fn.currentRowIndex = Fn.getRowIndex(Fn.table,json.message);
                                 window.Fn.loadData();
                                 if (parent.M) {
                                     parent.M.loadCatTree();
                                 }
                             } else {
                                 parent.M.alert(json.message, function () {
                                     location.replace('?module=category&action=all');
                                 });
                             }
                         } else {
                             parent.M.alert(json.message);
                         }
                     });
            }
        };

</script>


</body>
</html>
